package commands;

import nanoxml.XMLElement;
import utils.ITransmittable;

/**
 * This command represents a notification that a player 
 * in the game disconnected.
 */
public class CommandPlayerDisconnected implements ITransmittable
{
	private final static String ATTR_USERNAME = "Username";
	private final static String ATTR_TABLE_NUM = "TableNum";
	
	private String username = null; 
	private int    tableNum;
	
	
	public CommandPlayerDisconnected (String username, int tableNum)
	{
		this.username = username;
		this.tableNum = tableNum;
	}
	
	public CommandPlayerDisconnected(XMLElement command)
	{
		this((String)command.getAttribute(ATTR_USERNAME), command.getIntAttribute(ATTR_TABLE_NUM));
	}


	@Override
	public XMLElement toXML()
	{
		XMLElement message = new XMLElement();
		message.setName(Commands.PLAYER_DISCONNECTED);
		message.setAttribute(ATTR_USERNAME, username);
		message.setAttribute(ATTR_TABLE_NUM, tableNum);
		
		return message;
	}
	
	public String getUsername()
	{
		return username;
	}
	
	public int getTableNum()
	{
		return tableNum;
	}
}
